package org.study.tomcat_study.demo.simple;

import java.io.IOException;
import java.io.InputStream;

public class Request {

	private InputStream input;
	
	private int _2MB = 2<<10;
	
	private String uri;
	public Request(InputStream input) {
		this.input = input;
	}
	
	public void parse() {
		StringBuffer request = new StringBuffer(_2MB);
		int i;
		byte[] buffer= new byte[_2MB];
		try {
			i= input.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
			i=-1;
		}
		uri = parseUri(new String(buffer));
	}
	
	private String parseUri(String requestString) {
		int index1,index2;
		index1 = requestString.indexOf(' ');
		if(index1!=-1) {
			index2 = requestString.indexOf(' ',index1+1);
			if(index2>index1)
				return requestString.substring(index1+1, index2);
		}
		return null;
	}
	
	public String getUri() {
		return uri==null?"":uri;
	}
	
}
